﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace ConsoleApp1
{
    /*
     * 订单详细信息，包括订单简单信息，订单所有货物的种类，单价，订购数量及订单总金额
    */
    public class OrderDetail
    {
        [Key]
        public string goodsName { get; set; }

        public Goods goods;
        
        public string goodsPrice;
        public int quantity;
        public OrderDetail(Goods g, int q)
        {
            goods = g;
            quantity = q;
        }
        public double Amount { get => goods.getPrice() * quantity; }
        public string GoodsName { get => goods.Name; set => goodsName = goods.Name; }
        public string GoodsPrice { get => goods.getPrice().ToString(); set => goodsPrice = goods.getPrice().ToString(); }
        public int Quantity { get => quantity; set => quantity = value; }
       
       

        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder("");
            stringBuilder.Append("Goods name: ");
            stringBuilder.Append($"{goods.Name}  Goods quantity: {quantity}");
            return  stringBuilder.ToString();
        }
        public override bool Equals(object obj)
        {
            OrderDetail detail = (OrderDetail)obj;
            return ToString().Equals(detail.ToString());
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }
    }
}
